using System;
using System.Xml.Serialization;

namespace Practical.SharePoint.Base.WebParts
{
    public class MySite : IComparable
    {
        [XmlAttribute]
        public Guid Id { get; set; }

        [XmlAttribute]
        public string Url { get; set; }

        [XmlAttribute]
        public string Title { get; set; }

        override public string ToString()
        {
            return Title;
        }

        public int CompareTo(object obj)
        {
            string s1 = this.Title;
            string s2 = ((MySite)obj).Title;
            return String.Compare(s1, s2,StringComparison.CurrentCulture);
        }

        public static int Compare(MySite left, MySite right)
        {
            if (object.ReferenceEquals(left, right))
            {
                return 0;
            }
            if (object.ReferenceEquals(left, null))
            {
                return -1;
            }
            if (object.ReferenceEquals(right, null))
            {
                return -1;
            }
            return left.CompareTo(right);
        }

        public bool Equals(MySite other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id.Equals(Id) && Equals(other.Url, Url) && Equals(other.Title, Title);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (MySite)) return false;
            return Equals((MySite) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = Id.GetHashCode();
                result = (result*397) ^ (Url != null ? Url.GetHashCode() : 0);
                result = (result*397) ^ (Title != null ? Title.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(MySite left, MySite right)
        {
            if (object.ReferenceEquals(left, null))
            {
                return object.ReferenceEquals(right, null);
            }
            return left.Equals(right);
        }
        public static bool operator !=(MySite left, MySite right)
        {
            return !(left == right);
        }
        public static bool operator <(MySite left, MySite right)
        {
            return (Compare(left, right) < 0);
        }
        public static bool operator >(MySite left, MySite right)
        {
            return (Compare(left, right) > 0);
        }
    }
}